#!/bin/bash
# -*- coding: UTF-8 -*-
rm -fr $1

for i in {1..1}
do
	echo fzm | sudo -S python Mysql.py > mysql.result 2>&1 &
	echo fzm | sudo -S python redis.py > redis.result &
	echo fzm | sudo -S python apache2.py > apache2.result 2>&1 &
	
	wait
	
	# 查看apache2和redis是否执行成功
	ApacheLabel=`tail -n 2 apache2.result | head -n 1 | awk '{print $1}'`
	RedisLabel=`tail -n 1 redis.result | awk -F ':' '{print $1}'`

	while [[ "$ApacheLabel" != "100%" || "$RedisLabel" != "Redis" ]]
	do
		echo fzm | sudo -S python Mysql.py > mysql.result 2>&1 &
		echo fzm | sudo -S python redis.py > redis.result &
		echo fzm | sudo -S python apache2.py > apache2.result 2>&1 &
	
		wait
		ApacheLabel=`tail -n 2 apache2.result | head -n 1 | awk '{print $1}'`
		RedisLabel=`tail -n 1 redis.result | awk -F ':' '{print $1}'`
	done
	
	echo "第$i次测试:" >> $1
	tail -n 1 mysql.result >> $1
	tail -n 1 redis.result >> $1
	tail -n 1 apache2.result >> $1
done
